import http from './interface'

/**
 * 将业务所有接口统一起来便于维护
 * 如果项目很大可以将 url 独立成文件，接口分成不同的模块
 * 
 */

// 单独导出(测试接口) import {test} from '@/common/vmeitime-http/'
export const test = (data) => {
	/* http.config.baseUrl = "http://localhost:8080/api/"
	//设置请求前拦截器
	http.interceptor.request = (config) => {
		config.header = {
			"token": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
		}
	} */
	//设置请求结束后拦截器
	http.interceptor.response = (response) => {
		console.log('个性化response....')
		//判断返回状态 执行相应操作
		return response;
	}
	return http.request({
		baseUrl: 'https://unidemo.dcloud.net.cn/',
		url: 'ajax/echo/text?name=uni-app',
		dataType: 'text',
		data,
	})
}

export const users = () => {
	http.interceptor.request = (config) => {
		config.header = {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	}
	return http.request({
		url: 'wxapp/users',
		method: 'GET',
		data: {},
	})
}

export const userCheck = (data) => {
	http.interceptor.request = (config) => {
		config.header = {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	}
	return http.request({
		url: 'wxapp/check_user',
		method: 'POST',
		data,
	})
}

// 登录
export const loginRequest = (data) => {
	http.interceptor.request = (config) => {
		config.header = {
			'Content-Type': 'application/x-www-form-urlencoded'
		}
	}
	return http.request({
		url: 'wxapp/auth',
		method: 'POST',
		data,
	})

}

// 轮播图
export const banner = (data) => {
	return http.request({
		url: '/banner/36kr',
		method: 'GET',
		data,
		// handle:true
	})
}


// 首页信息
export const appInfo = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'goods/get_detail',
		method: 'GET',
		data,
		// handle:true
	})
}


// 更新信息
export const updateUserInfo = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'user/update_info',
		method: 'POST',
		data,
		// handle:true
	})
}

// 个人信息
export const userInfo = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'user/info',
		method: 'GET',
		data,
	})
}

export const toast = (data) => {
	return http.request({
		url: 'wxapp/toast',
		method: 'GET',
		data,
	})
}

export const getviewer = (data) => {
	return http.request({
		url: 'wxapp/getviewer',
		method: 'GET',
		data,
	})
}


// 邀请列表信息
export const inviteList = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'member/withdraw/invitelist',
		method: 'GET',
		data,
	})
}

// 红包
export const redpacketList = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'user/redpacket/list',
		method: 'GET',
		data,
	})
}


// 红包
export const redpacketInfo = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token,
				'Content-Type': 'application/x-www-form-urlencoded'
			}
		}
	}
	return http.request({
		url: 'member/withdraw/submit',
		method: 'POST',
		data,
	})
}


// 领取红包
export const drawRedpacket = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'user/redpacket/draw',
		method: 'POST',
		data,
	})
}


// 领取红包
export const redpacketBalance = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'user/redpacket/balance',
		method: 'POST',
		data,
	})
}


// 创建订单支付
export const orderCreate = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'order/create/share_order',
		method: 'POST',
		data,
	})
}

export const orderSubmit = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token,
				'Content-Type': 'application/x-www-form-urlencoded'
			}
		}
	}
	return http.request({
		url: 'order/create/submit',
		method: 'POST',
		data,
	})
}

export const orderPay = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token,
				'Content-Type': 'application/x-www-form-urlencoded'
			}
		}
	}
	return http.request({
		url: 'order/pay',
		method: 'GET',
		data,
	})
}


// 取消订单支付
export const orderCancel = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'order/cancel',
		method: 'POST',
		data,
	})
}


// 创建海报
export const posterCreate = (data) => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token
			}
		}
	}
	return http.request({
		url: 'goods/poster/getimage',
		method: 'POST',
		data,
	})
}

export const getBgm = () => {
	return http.request({
		url: 'wxapp/getbgm',
		method: 'GET',
		data: {}
	})
}

export const queryCompleteOrder = () => {
	let token = uni.getStorageSync("token")
	if (token) {
		console.log("已登录 ", token)
		http.interceptor.request = (config) => {
			config.header = {
				"Authorization": "Basic " + token,
				'Content-Type': 'application/x-www-form-urlencoded'
			}
		}
	}
	return http.request({
		url: 'order/op/query',
		method: 'GET',
		data: {}
	})
}


// 默认全部导出  import api from '@/common/vmeitime-http/'
export default {
	test,
	banner,
	appInfo,
	userInfo,
	loginRequest,
	updateUserInfo,
	inviteList,
	redpacketList,
	orderCreate,
	orderCancel,
	redpacketInfo,
	posterCreate,
	drawRedpacket,
	redpacketBalance,
	userCheck,
	users,
	orderSubmit,
	orderPay,
	toast,
	getviewer,
	getBgm,
	queryCompleteOrder
}